<template>
  <el-dialog v-dialogDrag v-if="popenevTVisible" title="阅文意见" :close-on-click-modal="false" :before-close="handleCancel" :visible.sync="popenevTVisible" width="900px">
    <!-- 自定义标题 -->
    <template slot="title">
      <div class="custom-header hc-text">
        <span class="header-title">
          阅文意见
        </span>
        <div class="notion-type">
          <div style="margin-right:10px">
            <span v-show="dlyj == 1">代签意见</span>
          </div>
          <div v-if="isDqyj" style="margin-right:10px">
            <span>流程节点：</span>
            <el-select :value="notionForm.nodeId" style="width:150px" @change="onNodeIdChange">
              <el-option v-for="( item, index ) in nodeList" :key="index" :label="item.nodeId" :value="item.nodeId">
              </el-option>
            </el-select>
          </div>
          <div>
            <span>意见类型：</span>
            <el-select v-model="notionForm.notionType" style="width:150px" default-first-option @change="onNotionTypeChange">
              <el-option v-for="( item, index ) in notionTypeList" :key="index" :label="item.type" :value="item.type">
              </el-option>
            </el-select>
          </div>
          <div v-if="isDqyj" style="margin-left:10px">
            <span>{{behalfPeopleLabel}}：</span>
            <el-select v-model="notionForm.personUnid" style="width:150px" default-first-option>
              <el-option v-for="( item, index ) in dqyjPersonList" :key="index" :label="item.personCommonname" :value="item.unid">
              </el-option>
            </el-select>
          </div>
        </div>
      </div>
    </template>
    <!-- 请 部门 人员 办理方式 阅文意见快捷选项 -->
    <div class="content-select hc-text" v-show="!onlyInput">
      <!-- 请 -->
      <div class="invite-box">
        <div class="box-title">{{ VUE_APP_CHOICE_NOTION.qing.title || '请' }}</div>
        <div class="box-list">
          <el-scrollbar class="scorll-Y">
            <div class="box-item" :class="{ active: item == nowSelectObj.qing }" @click="addContent(item, 'qing')" v-for="( item, index ) in DICT_xtsz_qing" :key="index">
              {{ item }}
            </div>
          </el-scrollbar>
        </div>
      </div>
      <!-- 部门 -->
      <div class="org-box" v-show="VUE_YWYJ_SHOW_ORG">
        <div class="box-title">{{ VUE_APP_CHOICE_NOTION.bm.title || '部门' }}</div>
        <div class="box-list">
          <el-scrollbar class="scorll-Y">
            <el-tree ref="tree" :data="orgTree" class="filter-tree mt-10" :default-checked-keys="[orgUnid]" :props="replaceFields" :load="loadOrgNode" :lazy="orgLazy" :node-key="replaceFields.value" :default-expanded-keys="expandKeys" :highlight-current="true" :expand-on-click-node="false" :check-on-click-node="true" :check-strictly="true" @check="handleOrgSelect">
            </el-tree>
          </el-scrollbar>
        </div>
      </div>
      <!-- 人员 -->
      <div class="person-box">
        <div class="box-title">{{ VUE_APP_CHOICE_NOTION.ry.title || '人员' }}</div>
        <div class="box-list">
          <!-- 搜索框 -->
          <el-input size="mini" class="person-search" placeholder="搜索人员名称" v-model="searchoPersonkey">
            <i slot="prefix" class="el-input__icon el-icon-search"></i>
          </el-input>
          <el-scrollbar class="scorll-Y" ref="scrollMenuRef" style="height:168px">
            <div class="box-item" :class="{ active: nowSelectObj.personCommonname && ((item.personCommonname == nowSelectObj.personCommonname) || (item.nickName == nowSelectObj.personCommonname)) }" @click="addPersonContent(item)" v-for="( item, index ) in showPersonList" :key="index">
              {{ item.personCommonname }} {{item.dutyStr | showDutyStr}}
            </div>
          </el-scrollbar>
        </div>
      </div>
      <!-- 称谓为 -->
      <div class="cw-box" v-if="(VUE_APP_CHOICE_NOTION.cw && VUE_APP_CHOICE_NOTION.cw.show) || false">
        <div class="box-title">{{ (VUE_APP_CHOICE_NOTION.cw && VUE_APP_CHOICE_NOTION.cw.title) || '称谓' }}</div>
        <div class="box-list">
          <el-scrollbar class="scorll-Y">
            <div class="box-item" :class="{ active: item == nowSelectObj.cw }" @click="addContent(item, 'cw')" v-for="( item, index ) in DICT_xtsz_cw" :key="index">
              {{ item }}
            </div>
          </el-scrollbar>
        </div>
      </div>

      <!-- 办理方式 -->
      <div class="way-box">
        <div class="box-title">{{ VUE_APP_CHOICE_NOTION.blfs.title || '处理方式' }}</div>
        <div class="box-list">
          <el-scrollbar class="scorll-Y">
            <div class="box-item" :class="{ active: item == nowSelectObj.blfs }" @click="addContent(item, 'blfs')" v-for="( item, index ) in DICT_xtsz_blfs" :key="index">
              {{ item }}
            </div>
          </el-scrollbar>
        </div>
      </div>
    </div>

    <!-- 阅文意见内容 -->
    <div class="notion-content hc-text">
      <el-input ref="notionInput" class="input-content" rows="5" type="textarea" placeholder="请输入内容" v-model="notionForm.content">
      </el-input>
    </div>

    <!-- 确定后端打开送问框 -->
    <div class="notion-bottom" style="margin-top:10px" v-if="!isDqyj && !ismhsw">
      <el-checkbox v-model="showSendFlowView" class="hc-text">确定后打开送文框</el-checkbox>
      <!-- 阅文密码  -->
      <el-form ref="passForm" v-if="userInfo.ywyjjymm && userInfo.ywyjjymm == 1" :model="passForm" :rules="passRule" label-width="0">
        <el-form-item style="margin-bottom:0" prop="notionPass">
          <el-input size="mini" style="margin-left:0px;width:200px" class="input-password" type="password" auto-complete="off" placeholder="请输入阅文意见密码" v-model="passForm.notionPass">
          </el-input>
        </el-form-item>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <div class="dialog-footer__left">
        <el-link v-if="showSxYwyj && showSxYwyjLink" @click="dialogVisible = true">手写意见</el-link>
      </div>
      <div class="dialog-footer__right">
        <el-button type="primary" v-if="showSxYwyj && !showSxYwyjLink" @click="dialogVisible = true">手写意见</el-button>
        <el-button type="primary" :loading="confirmLoading" @click="handleOk">确定</el-button>
        <el-button @click="handleCancel">取 消</el-button>
      </div>

    </div>
    <!-- 手写意见弹窗 -->
    <SignatureDialog title="手写意见" :visible.sync="dialogVisible" :confirm="onSignatureConfirm" />
  </el-dialog>
</template>

<script>
import { writeNotion, writeNotionWithImage } from "../../api/common/flowsend";
import { getNotionType, saveNotion, changeYwjy, getNodeList, getPersonListByNodeId } from "../../api/common/notion";
import { getPersonList } from "../../api/system/person/api";
import
{
  getCompanyTree, getOrgListByParentId
} from "../../api/module/systemOrg/systemOrg.js";
import { mapState, mapActions, mapGetters } from "vuex";
import { getNodeId } from "../../api/common/getNodeId";
import FileUpload from "../../components/fileUpload";
import { checkNotionPass } from "../../api/module/systemPerson/systemPerson";
import PinYinMatch from "pinyin-match";
import SignatureDialog from "../SignatureDialog";
import
{
  getSendFlowNode,
  sendDoc
} from "../../api/common/flowsend";
export default {
  components: {
    FileUpload,
    SignatureDialog,
  },
  data()
  {
    return {
      isDqyj: false,//是否是代签意见
      dqyjPersonList: [],//代签阅文可选人员列表
      mj: null,//密级
      bt: "",//表单标题
      //代签阅文意见被代签标题
      behalfPeopleLabel: window.HC_config.VUE_TWYJ_BEHALF_PEOPLE_LABEL || '被代签人',
      //阅文意见代签自动选中流程节点
      isHehalfAutoSelectedNode: window.HC_config.VUE_YWYJ_BEHALF_AUTO_SELECTED_NODE || false,
      //是否显示手写阅文意见
      showSxYwyj: window.HC_config.VUE_APP_SX_YWYJ || false,
      //手写阅文意见link显示
      showSxYwyjLink: window.HC_config.VUE_SX_YWYJ_LINK || false,
      //阅文意见是否显示部门
      VUE_YWYJ_SHOW_ORG: window.HC_config.VUE_YWYJ_SHOW_ORG == undefined ? true : window.HC_config.VUE_YWYJ_SHOW_ORG,
      VUE_APP_CHOICE_NOTION: window.HC_config.VUE_APP_CHOICE_NOTION || {
        qing: {
          title: "请",
          isInput: true,
        },
        bm: {
          title: "部门",
          isInput: true,
        },
        ry: {
          title: "人员",
          isInput: true,
        },
        blfs: {
          title: "办理方式",
          isInput: true,
        },
      },
      //流程unid
      flowstructureunid: null,
      //流程节点unid 供代签意见选择
      nodeId: "",
      //阅文意见密码
      passForm: {
        notionPass: "",
      },
      expandKeys: [],
      passRule: {
        notionPass: [{ required: true, message: '请输入密码', trigger: 'blur' }],
      },
      parame: {
        pageNo: 1,
        pageSize: 100,
        delFlag: 0,
        state: 0,
        orgUnid: null,
      },
      orgUnid: null,
      //promise状态  
      promiseStatus: null,
      //是否显示弹窗
      popenevTVisible: false,
      //可选的意见类型
      notionTypeList: [],
      //人员列表
      personList: [],
      //机构列表
      orgTree: [],
      //总数
      totalCount: 0,
      //人员搜索关键字
      searchoPersonkey: null,
      notionForm: {
        content: "",
        published: 0,
        notionType: null,
        nodeId: null,
        personUnid: null
      },
      //阅文意见图片地址
      notionImageUrl: "",
      //图片base64
      notionImageBase64: null,
      replaceFields: {
        label: "orgCommonname",
        value: "unid",
        isLeaf: 'leaf'
      },
      nowSelectObj: {
        orgCommonname: null,
        personCommonname: null,
        qing: null,//当前显示的请
        blfs: null,//当前显示的办理方式
      },
      //是否打开送文框
      showSendFlowView: false,
      currentNotion: null,//修改的项
      dlyj: null,//是否是代录意见 0否 1是
      confirmLoading: false,
      //阅文意见是否结束(最后是办理方式即为结束)
      isContentEnd: false,
      contentKeyList: [],
      //代签意见可选节点列表
      nodeList: [],
      ismhsw: false, //是否模糊送文
      sendCallBack: null,//模糊送文后回调事件
      sendDocPeronsList: [], //发送人员列表
      isaibw: false,//是否ai办文
      //是否显示手签意见弹窗
      dialogVisible: false,
      //机构懒加载
      orgLazy: window.HC_config.VUE_APP_ORGLAZY,
      //是否只显示文本框
      onlyInput:false,
      //自动打开手写意见
      autoOpenSignature: false
    }
  },
  filters: {
    showDutyStr(P_DutyStr)
    {
      let valueToReturn = "";
      if (P_DutyStr)
      {
        let DutyArr = P_DutyStr.split(",");
        valueToReturn = "(" + DutyArr[0] + ")";
      }
      return valueToReturn;
    }
  },
  computed: {
    ...mapState("dict", ["DICT_xtsz_blfs", "DICT_xtsz_qing", "DICT_xtsz_cw"]),
    ...mapGetters(["userInfo"]),
    showPersonList()
    {
      if (!this.searchoPersonkey)
      {
        return this.personList;
      }
      let tampArr = this.personList.filter(item =>
      {
        return item.personCommonname.indexOf(this.searchoPersonkey) > -1 || PinYinMatch.match(item.personCommonname, this.searchoPersonkey);
      })
      return tampArr;
    }
  },
  created()
  {
    //获取办理方式列表
    this.getCs({
      dictKey: "DICT_xtsz_blfs",
      code: "xtsz_blfs"
    })

    //获取请方式列表
    this.getCs({
      dictKey: "DICT_xtsz_qing",
      code: "xtsz_qing"
    })

    //获取称谓
    this.getCs({
      dictKey: "DICT_xtsz_cw",
      code: "xtsz_cw"
    })
    //人员默认选择本机构人员
    this.orgUnid = this.userInfo.orgUnid;
    this.parame.orgUnid = this.orgUnid;
    //获取人员列表
    this.getPersonList();
    //获取机构列表
    if (!this.orgLazy)
    {
      this.getOrgTree();
    }
    let ywhdkswk = this.userInfo.ywhdkswk == 1 ? true : false;
    this.showSendFlowView =
      JSON.parse(localStorage.getItem("showSendFlowView_" + this.userInfo.unid)) || ywhdkswk;
  },
  methods: {
    ...mapActions("dict", ["getCs"]),
    show(showData, config)
    {
      if (config)
      {
        //是否只显示文本框
        this.onlyInput = config.onlyInput || false;
        this.autoOpenSignature  = config.autoOpenSignature || false
      }
      this.sendDocPeronsList = [];
      this.bt = showData.bt;
      if (showData.showSendFlowView)
      {
        this.showSendFlowView = showData.showSendFlowView;
      }
      this.isDqyj = showData.isDqyj || false;

      if (this.isDqyj)
      {
        this.showSendFlowView = false;
      }
      this.sendCallBack = showData.sendCallBack;
      this.mj = showData.mj || "";
      this.flowstructureunid = showData.flowstructureunid;
      this.currentNotion = showData.currentNotion || null;
      this.notionForm.unid = showData.unid; //表单unid
      this.notionForm.moudleName = showData.moduleName; //模块名
      this.notionForm.wjmj = showData.wjmj; //
      this.notionForm.notionId = showData.notionId; //意见的unid 存在则为编辑
      this.notionForm.content = showData.content; //意见内容
      this.notionForm.notionType = showData.type;//意见类型
      this.notionForm.formType = showData.formType; //
      this.notionForm.published = showData.published || 0;
      this.dlyj = showData.dlyj; //是否是代录意见
      this.isaibw = showData.aibw; //是否AI办文 即签完意见后 自动调用完成接口
      this.ismhsw = showData.ismhsw;//是否模糊送文
      if (!this.isDqyj)
      {
        //正常签阅文意见逻辑
        if (showData.notionId)
        {
          this.popenevTVisible = true;
          this.notionTypeList = [
            {
              type: this.notionForm.notionType,
              dlyj: this.dlyj
            }];
        } else
        {
          if (!showData.type)
          {
            this.$message.info("该节点无需签署阅文意见");
            return
          }
          this.popenevTVisible = true;
          if (showData.formType)
          {
            let notionTypeArr = showData.type.split(",");
            let dyljArr = [];
            if (showData.dlyj && typeof showData.dlyj == "string")
            {
              dyljArr = showData.dlyj.split(',');
              this.dlyj = dyljArr[dyljArr.length - 1]; //是否是代录意见
            }
            else
            {
              this.dlyj = showData.dlyj || 0;
            }

            this.notionForm.notionType = notionTypeArr[notionTypeArr.length - 1];
            this.notionTypeList = [];
            notionTypeArr.forEach((element, index) =>
            {
              this.notionTypeList.push({
                type: element,
                dlyj: dyljArr.length > 0 ? dyljArr[index] : 0
              })
            });
          }
          this.$nextTick(() =>
          {
            console.log(this.$refs);
            this.$refs.notionInput.focus();
          })

          this.getNodeId();
        }
      }
      else
      {
        this.notionForm.content = "";
        this.popenevTVisible = true;
        //代签阅文意见逻辑 查询可签的节点和人员
        this.getProxyNodeList();
        this.$nextTick(() =>
        {
          console.log(this.$refs);
          this.$refs.notionInput.focus();
        })
      }
      this.$nextTick(() =>
      {
        this.$refs.scrollMenuRef.wrap.addEventListener("scroll", this.scrollMenu);
      })

      if(this.autoOpenSignature)
      {
        //打开手写意见弹窗
        this.dialogVisible = true;
      }
      // 创建promise
      return new Promise((resolve, reject) =>
      {
        this.promiseStatus = {
          resolve,
          reject,
        };
      });
    },
    //查询可代签的节点和人员
    getProxyNodeList()
    {
      getNodeList(
        {
          flowId: this.flowstructureunid
        }
      ).then(res =>
      {
        this.nodeList = res.result || [];
        console.log("代签的节点和人员", this.nodeList);
        //代签阅文意见 自动选中节点
        if (this.isHehalfAutoSelectedNode)
        {
          const nodeItem = this.nodeList.find(preItem => preItem.notionType == this.notionForm.notionType);
          console.log("查找节点啊，然后选择红节点", nodeItem);
          if (nodeItem)
          {
            this.onNodeIdChange(nodeItem.nodeId);
          }
        }
      })
    },
    //监听意见类型选择
    onNotionTypeChange(P_NotionType)
    {
      let findObj = this.notionTypeList.find(per_item =>
      {
        return per_item.type == P_NotionType;
      })
      if (findObj)
      {
        this.dlyj = findObj.dlyj;
      }
      this.getNodeId();
    },
    //监听节点选择
    onNodeIdChange(P_NodeId)
    {
      console.log(P_NodeId);
      let findObj = this.nodeList.find(pre_node =>
      {
        return pre_node.nodeId == P_NodeId;
      })
      this.notionForm.personUnid = null;
      console.log("监听节点选择=====>", findObj);
      if (findObj)
      {
        this.notionForm.nodeId = P_NodeId;
        if (findObj.personList)
        {
          this.notionForm.notionType = findObj.notionType;
          this.notionTypeList = [findObj.notionType];
          this.dqyjPersonList = findObj.personList || [];
        }
        else
        {
          this.notionForm.notionType = findObj.notionType;
          this.notionTypeList = [findObj.notionType];
          getPersonListByNodeId({
            flowId: this.flowstructureunid,
            mj: this.mj,
            nodeId: P_NodeId
          }).then(res =>
          {
            findObj.personList = res.result || [];
            this.dqyjPersonList = findObj.personList || [];
          })
        }
      }
    },
    /**
     * 获取当前登录人最新阅文意见
     */
    getNodeId()
    {
      getNodeId({ unid: this.notionForm.unid, type: this.notionForm.notionType, gxyj: (sessionStorage.getItem('gxyj') == 'true') }).then((res) =>
      {
        this.notionForm.content = res.result ? res.result.content : "";
      });
    },
    //获取意见可选类型
    getNotionType()
    {
      getNotionType({
        unid: this.notionForm.unid,
        modulename: this.notionForm.moudleName,
        sslb: this.notionForm.formType || ""
      }).then(res =>
      {
        this.notionTypeList = res.result || [];
      })
    },
    /**
     * 添加确定按钮
     */
    handleOk()
    {
      if (this.isDqyj)
      {
        if (!this.notionForm.nodeId)
        {
          this.$message.warning('请先选择要代签的节点');
          return
        }
        if (!this.notionForm.personUnid)
        {
          this.$message.warning('请先选择要代签的人员');
          return
        }
      }

      if (this.userInfo.ywyjjymm && this.userInfo.ywyjjymm == 1)
      {
        this.$refs.passForm.validate((valid) =>
        {
          console.log(valid);
          if (valid)
          {
            checkNotionPass({
              notionPass: window.btoa(this.passForm.notionPass),
            }).then(res =>
            {
              this.saveNotion();
            })
          } else
          {

          }
        })
      } else
      {
        this.saveNotion();
      }
    },
    /**
     * 保存阅文意见
     */
    saveNotion()
    {
      if (!this.notionForm.content)
      {
        this.$message.error("请输入意见")
        return
      }

      this.confirmLoading = true;
      let notionParam = {
        ownerIdent: this.userInfo.unid,
        docIdent: this.notionForm.unid,
        notionContent: this.notionForm.content,
        moduleName: this.notionForm.moudleName,
        flowstructureunid: this.flowstructureunid,
        sourceClient: "网页端",
        sslb: "",
        notionType: this.notionForm.notionType,
        gxyj: (sessionStorage.getItem('gxyj') == 'true'),
      };
      if (typeof this.notionForm.published != "undefined")
      {
        notionParam.published = 1;
      }
      if (this.currentNotion)
      {
        //编辑
        this.currentNotion.ident = this.currentNotion.unid;
        this.currentNotion.content = this.notionForm.content;
        this.currentNotion.flowstructureunid = this.flowstructureunid;
        this.currentNotion.dlyj = this.dlyj == 1 ? true : false;
        console.log(this.currentNotion);
        changeYwjy({
          wjbt: this.bt,
          notionItem: this.currentNotion,
          wjid: this.notionForm.unid,
          mkmc: this.notionForm.moudleName
        }).then(res =>
        {
          this.$message.success("阅文意见签写成功");
          this.destroyElement();
          localStorage.setItem("showSendFlowView_" + this.userInfo.unid, this.showSendFlowView);
          this.promiseStatus.resolve({ notionParam: notionParam, showSendFlowView: this.showSendFlowView });
        })
        // saveNotion( this.currentNotion ).then( ( res ) =>
        // {
        //   this.$message.success( "阅文意见签写成功" );
        //   this.destroyElement();
        //   localStorage.setItem( "showSendFlowView_" + this.userInfo.unid, this.showSendFlowView );
        //   this.promiseStatus.resolve( { notionParam: notionParam, showSendFlowView: this.showSendFlowView } );
        // } ).catch( err =>
        // {

        // } ).finally( () =>
        // {
        //   this.confirmLoading = false;
        // } );
      } else
      {
        notionParam.dlyj = this.dlyj == 1 ? true : false;
        if (this.isDqyj)
        {
          notionParam.wtrUnid = this.notionForm.personUnid;
        }
        //新增
        writeNotion(notionParam)
          .then((res) =>
          {
            this.$message.success("阅文意见签写成功");
            if (this.ismhsw && this.sendDocPeronsList.length > 1)
            {
              //需要模糊送文
              this.sendDoc();
            }
            else
            {
              this.destroyElement();
              localStorage.setItem("showSendFlowView_" + this.userInfo.unid, this.showSendFlowView);
              //   this.$emit("ok", notionParam);
              this.promiseStatus.resolve({ notionParam: notionParam, showSendFlowView: this.showSendFlowView, isaibw: this.isaibw });
            }
          })
          .catch(() =>
          {

          })
          .finally(() =>
          {
            this.confirmLoading = false;
          });
      }


    },
    handleCancel()
    {
      //清空勾选项
      this.promiseStatus.reject({
        msg: "取消",
      });
      this.destroyElement();
    },
    //添加顿号
    isAddDunhao(P_Key)
    {
      let m_prevKey = this.contentKeyList.length > 0 ? this.contentKeyList[this.contentKeyList.length - 1] : "";
      if (m_prevKey == "personCommonname" || (m_prevKey == "orgCommonname" && P_Key == "orgCommonname"))
      {
        return true;
      }
      return false;
    },
    addPersonContent(P_Person)
    {
      let dutyStr = "";
      if (P_Person.dutyStr)
      {
        let DutyArr = P_Person.dutyStr.split(",");
        dutyStr = DutyArr[0];
      }
      this.sendDocPeronsList.push(P_Person);
      this.addContent((P_Person.nickName || P_Person.personCommonname) + dutyStr, 'personCommonname');
    },
    /**
     * 添加请
     */
    addContent(item, key)
    {
      //快速选择会出现  undefined
      console.log("添加内容", item);
      if (!item)
      {
        return;
      }

      //快速点击会出现undefined
      this.notionForm.content = this.notionForm.content || "";
      if (this.nowSelectObj[key])
      {
        if (this.notionForm.content)
        {
          if (key == 'blfs')
          {
            this.notionForm.content += item;
            this.notionForm.content += window.HC_config.VUE_APP_NOTION_END ? window.HC_config.VUE_APP_NOTION_END : "";
            this.nowSelectObj = {};
          }
          else
          {
            // if(key == "qing"){
            //   this.notionForm.content = "";
            //   this.contentKeyList.length = 0;
            //   this.nowSelectObj = {};
            // }
            let addContent = "";
            if (key == 'orgCommonname' && this.VUE_APP_CHOICE_NOTION)
            {
              if (this.VUE_APP_CHOICE_NOTION.bm?.isInput)
              {
                addContent += item;
              }
            } else
            {
              addContent += item;
            }

            if (this.isAddDunhao(key))
            {
              this.notionForm.content += "、";
            }
            let m_prevKey = this.contentKeyList.length > 0 ? this.contentKeyList[this.contentKeyList.length - 1] : "";
            if (this.nowSelectObj.orgCommonname && m_prevKey == "personCommonname" && key == "personCommonname")
            {
              if (this.VUE_APP_CHOICE_NOTION.ry && this.VUE_APP_CHOICE_NOTION.ry.isAddOrg)
              {
                console.log("this.nowSelectObj.orgCommonname", this.nowSelectObj.orgCommonname);
                addContent = this.nowSelectObj.orgCommonname + addContent;
              }
            }
            this.notionForm.content += addContent;
          }
        } else
        {
          this.notionForm.content = item;

        }
      } else
      {
        // if (!this.notionForm.content || key == "qing") {
        //   this.notionForm.content = "";
        //   this.contentKeyList.length = 0;
        // }
        if (key == 'blfs')
        {
          this.notionForm.content += item;
          this.notionForm.content += window.HC_config.VUE_APP_NOTION_END ? window.HC_config.VUE_APP_NOTION_END : "";
          //清空
          this.nowSelectObj = {};
        }
        else
        {

          if (key == 'orgCommonname' && this.VUE_APP_CHOICE_NOTION)
          {
            if (this.VUE_APP_CHOICE_NOTION.bm?.isInput)
            {
              this.notionForm.content += item;
            }
          } else
          {
            this.notionForm.content += item;
          }
        }
      }

      this.contentKeyList.push(key);
      this.nowSelectObj[key] = item;
      this.$nextTick(() =>
      {
        this.$refs.notionInput.focus();
      })
    },
    //选择机构
    handleOrgSelect(selectKey, isCheck)
    {
      this.orgUnid = selectKey.unid;
      this.parame.pageNo = 1;
      this.parame.orgUnid = this.orgUnid;
      this.addContent(selectKey.orgCommonname, "orgCommonname");
      // this.$refs.tree.setCheckedKeys([selectKey.unid], true);
      this.getPersonList();
    },
    //监听滚动
    scrollMenu(e)
    {
      let poor = e.target.scrollHeight - e.target.clientHeight
      if (poor == parseInt(e.target.scrollTop) || poor == Math.ceil(e.target.scrollTop) || poor == Math.floor(e.target.scrollTop))
      {
        console.log("滚动到底");
        if (this.totalCount > this.personList.length)
        {
          this.loadMore();
        }
      }
    },
    //加载更多
    loadMore()
    {
      this.parame.pageNo++;
      this.loading = true;
      getPersonList(this.parame).then((res) =>
      {
        this.totalCount = res.result.totalCount || 0;
        this.personList.push(...(res.result.data || []));
      }).finally(() => { this.loading = false });
    },
    //获取人员列表
    getPersonList()
    {
      getPersonList(this.parame).then(res =>
      {
        this.totalCount = res.result.totalCount || 0;
        this.personList = res.result.data || [];
      })
    },
    //获取机构列表
    getOrgTree()
    {
      getCompanyTree(
        {
          type: "notion"
        }
      ).then(res =>
      {
        this.orgTree = res.result || [];
        this.orgUnid = this.userInfo.orgUnid;
        this.parame.orgUnid = this.orgUnid;
        this.expandKeys = [this.parame.orgUnid]
        this.$nextTick(() =>
        {
          this.$refs.tree.setCurrentKey(this.orgUnid);
        })
      })
    },
    //懒加载机构节点
    loadOrgNode(node, resolve)
    {
      let parentUnid = null;
      if (node.level !== 0)
      {
        parentUnid = node.data.unid
      }
      getOrgListByParentId({
        parentUnid: parentUnid
      }).then(res =>
      {
        let orgList = res.result || [];
        orgList.forEach(pre_org =>
        {
          pre_org.leaf = pre_org.subOrgNum && pre_org.subOrgNum > 0 ? false : true;
        })
        resolve(orgList);
      })
    },
    /**
    * cs 2022-4-8
    * 销毁组件
    */
    destroyElement()
    {
      this.popenevTVisible = false;
    },
    /**
     * 模糊送文
     */
    async sendDoc()
    {
      //消息模式
      let awakeMode = 0;
      if (this.sendDocPeronsList.length < 1)
      {
        this.$message.error("请选择发送的人员！");
        return;
      }
      const urlparam = {
        flowstructureunid: this.flowstructureunid,
        unid: this.notionForm.unid,
        awakeMode: awakeMode,
        // backlogUrl: this.moduleurl,
        bt: "",
        backlogUrl: this.$route.path,
        finalizeUnFinishTasks: false,
        moduleName: this.notionForm.moudleName,
        openBacklogTarget: "_blank",
        senderUser: "1",
        sslb: this.notionForm.formType,
        gxyj: (sessionStorage.getItem('gxyj') == 'true')
      };
      this.destroyElement();
      this.promiseStatus.resolve({ showSendFlowView: this.showSendFlowView, ismhsw: this.ismhsw, sendDocParam: urlparam, sendCallBack: this.sendCallBack, sendDocPeronsList: this.sendDocPeronsList });
    },
    //手签意见确认
    onSignatureConfirm(P_Base64)
    {
      P_Base64 = P_Base64.split(",")[1]; // 去掉 data:image/png;base64, 部分
      return new Promise((resolve, reject) =>
      {
        let notionParams = {
          docIdent: this.notionForm.unid,
          notionContent: "",
          moduleName: this.notionForm.moudleName,
          flowstructureunid: this.flowstructureunid,
          sslb: "",
          published: '',
          notionType: this.notionForm.notionType,
          sourceClient: "网页端",
          file: P_Base64,
        };
        writeNotionWithImage(notionParams)
          .then(res =>
          {
            this.$message.success("上传阅文意见签写成功");
            this.promiseStatus.resolve({ notionParam: notionParams, showSendFlowView: this.showSendFlowView, isaibw: this.isaibw });
            this.destroyElement();
            localStorage.setItem("showSendFlowView_" + this.userInfo.unid, this.showSendFlowView);
            resolve();
          })
          .catch(P_Error =>
          {
            console.error("[图片阅文意见接口异常]", P_Error);
            this.$message.error("上传阅文意见失败");
            reject();
          });
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.custom-header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  padding-right: 50px;

  .header-title {
    line-height: 24px;
    font-size: 18px;
    color: #303133;
    cursor: move;
  }
}

.notion-type {
  display: flex;
  justify-content: space-between;
  align-items: center;
  line-height: 36px;
}

.content-select {
  display: flex;
  height: 242px;
  margin-top: 10px;

  .invite-box {
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    overflow: hidden;
    flex: 1;
    margin-right: 10px;
  }

  .org-box {
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    overflow: hidden;
    flex: 3;
    margin-right: 10px;
  }

  .person-box {
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    overflow: hidden;
    flex: 2;
    margin-right: 10px;
  }

  .cw-box {
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    overflow: hidden;
    flex: 2;
    margin-right: 10px;
  }

  .way-box {
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    overflow: hidden;
    flex: 2;
  }

  .box-title {
    height: 37px;
    line-height: 37px;
    background-color: #eeeeee;
    padding-left: 5px;
  }

  .box-list {
    height: 195px;

    .box-item {
      margin-bottom: 3px;
      padding-left: 10px;
      cursor: pointer;

      &.active {
        background: #1890ff;
        color: #fff;

        &:hover {
          background: #1890ff;
          color: #fff;
        }
      }

      &:hover {
        background: #edf6ff;
      }
    }

    .scorll-Y {
      height: 100%;

      ::v-deep .el-scrollbar__wrap {
        overflow-x: hidden;
      }
    }
  }
}

.notion-content {
  margin-top: 10px;

  ::v-deep .el-textarea__inner {
    font-size: 18px;
  }
}

.person-search {
  width: 98%;
  margin: 5px 1% 0;
  height: 26px;
  margin-bottom: 5px;

  ::v-deep .el-input__inner {
    border-radius: 100px;
  }
}

.notion-bottom {
  display: flex;
  justify-content: center;
  justify-content: space-between;
}

.dialog-footer {
  display: flex;
  justify-content: space-between;
  .dialog-footer__left {
    display: flex;
    padding-left: 24px;
  }
  .dialog-footer__right {
    display: flex;
  }
}
</style>